<?php
/**
 * Smarty plugin
 * @package Smarty
 * @subpackage plugins
 */


/**
 * Smarty indent modifier plugin
 *
 * Type:     modifier<br>
 * Name:     indent<br>
 * Purpose:  indent lines of text
 * @link http://smarty.php.net/manual/en/language.modifier.indent.php
 *          indent (Smarty online manual)
 * @param string
 * @param integer
 * @param string
 * @return string
 */
function smarty_function_list_line($params, &$smarty)
{
    $p = array_merge(array(
      'name'        =>  ''
     ,'id'          =>  ''
     ,'class'       =>  ''
     ,'style'       =>  ''
     ,'more'        =>  ''
     ,'label'       =>  ''
     ,'value'       =>  ''
     ,'left'        =>  true
     ,'right'       =>  true
     ,'tag'         =>  'span'
     ,'root'        =>  'li'
     ,'test'        =>  'pas_vide'
     ,'root_class'  =>  'profil mod'
     ,'l_class'     =>  'left'
     ,'r_class'     =>  'left'
     ,'before'      =>  ''
     ,'prepend'     =>  ''//<hr />'
     ,'append'      =>  ''
     ,'after'       =>  ''
     ,'hideOnEmpty' =>  true
     ),$params);


    foreach(array('more','label','tag','before','after','prepend','append') as $arg){
      if(!isset($p["l_$arg"])) $p["l_$arg"] = '';
      if(!isset($p["r_$arg"])) $p["r_$arg"] = '';
    }

    if(empty($p['test']) || (bool) $p['test'] ==false){
      return '';
    }
    
    if($p['hideOnEmpty'] && empty($p['value'])){
      return '';
    }
    
    $r_args = $l_args = $root_args = '';
    
    foreach (array('id','name','class','style') as $arg){

      if(!empty($p["r_$arg"]) || !empty($p[$arg])){
        $r_args .= ($r_args=='' ? '' : ' ').$arg.'="'.(!empty($p[$arg]) ? $p[$arg] : $p["r_$arg"]).'"';
      }

      if(!empty($p["l_$arg"])){
        $l_args .= ($l_args=='' ? '' : ' ').$arg.'="'.$p["l_$arg"].'"';
      }

      if(!empty($p["root_$arg"])){
        $root_args .= ($root_args=='' ? '' : ' ').$arg.'="'.$p["root_$arg"].'"';
      }

    }

    if(!empty($p['l_label'])){
      $p['label'] = $p['l_label'];
    }
    if(!empty($p['l_value'])){
      $p['value'] = $p['l_value'];
    }

    $l_tag    = (!empty($p['l_tag'])    ? $p['l_tag']     : $p['tag']);
    $r_tag    = (!empty($p['r_tag'])    ? $p['r_tag']     : $p['tag']);
    $root_tag = (!empty($p["root_tag"]) ? $p["root_tag"]  : $p["root"]);
    
    $html  =  '';

    // Noeud parent - ouverture
    $html .=  $p['before'];
    if(!empty($root_tag)){
      $html .=  "<$root_tag $root_args {$p["id"]}>";
    }
    $html .=  $p['prepend'];

    if($p['left']){
      //Partie gauche - libellé
      $html .=  $p['l_before'];
      $html .=  "<$l_tag $l_args {$p['l_more']} >";
      $html .=  $p['l_prepend'];
      $html .=  $p['label'];
      $html .=  $p['l_append'];
      $html .=  "</$l_tag>";
      $html .=  $p['l_after'];
    }

    if($p['right']){
      // Partie droite - valeur
      $html .=  $p['r_before'];
      $html .=  "<$r_tag $r_args {$p['r_more']} >";
      $html .=  $p['r_prepend'];
      $html .=  $p['value'];
      $html .=  $p['r_append'];
      $html .=  "</$r_tag>";
      $html .=  $p['r_after'];
    }

    // Noeud parent - fermeture
    $html .=  $p['append'];
    if(!empty($root_tag)){
      $html .=  "</{$root_tag}>";
    }
    $html .=  $p['after'];

    return $html;
}

?>
